<table id="dg-zh" style="height:100%;width: 100%;">
    <thead>
    <tr>
        <th data-options="field:'ZH_LX',width:100">账户类型</th>
        <th data-options="field:'ZH_MC',width:100">账户名称</th>
        <th data-options="field:'ZH_BH',width:100">账号</th>
        <th data-options="field:'XY_BZ',formatter:BzFormatter,width:100">选用标志</th>
        <th data-options="field:'YX_BZ',formatter:BzFormatter,width:100">有效标志</th>
        <th data-options="field:'LRSJ',formatter:DateTimeFormatter,width:100">创建日期</th>
    </tr>
    </thead>
</table>

<div id="tb-zh">
    <table cellpadding="0" cellspacing="0" style="width:100%">
        <tr class="clearfix">
            <td class="luck-tool-button">
                账户类型: <select class="easyui-combobox" panelHeight="auto" data-options="prompt:'请选择',url:'${ctxPath}/dm/zhlx', method:'get', valueField:'dicDm', textField:'dicMc',editable:true,width:150" id="sel_zhlxs" name="sel_zhlxs"></select>
                账户名称: <input class="easyui-textbox" name="zhmc" id="zhmc" style="width:150px">
                账户账号: <input class="easyui-textbox" name="zhbh" id="zhbh" style="width:150px">
                <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="zh_tool.search();">${i18n('btn.search')}</a>
            </td>
            <td class="luck-tool-button luck-text-right luck-right">
                <a href="#" class="easyui-linkbutton button-blue" plain="true" onclick="zh_tool.add();"><i class="fa fa-plus fa-lg"></i>&nbsp;${i18n('btn.new')}</a>
                <a href="#" class="easyui-linkbutton button-orange" plain="true" onclick="zh_tool.edit();"><i class="fa fa-edit fa-lg"></i>&nbsp;${i18n('btn.edit')}</a>
                <a href="#" class="easyui-linkbutton button-red" plain="true" onclick="zh_tool.delete();"><i class="fa fa-close fa-lg"></i>&nbsp;${i18n('btn.delete')}</a>
                <a href="#" class="easyui-linkbutton button-info" plain="true" onclick="zh_tool.import();"><i class="fa fa-file-excel-o fa-lg"></i>&nbsp;${i18n('btn.import')}</a>
                <a href="#" class="easyui-linkbutton button-green" plain="true" onclick="zh_tool.download();"><i class="fa fa-download fa-lg"></i>&nbsp;${i18n('btn.mb')}</a>
            </td>
        </tr>
    </table>
</div>
<script>
    var dg_zh;
    $(function () {
        dg_zh = rsdp.createDataGrid({
            tid: "dg-zh",
            url: "${ctxPath}/system/zh/manage",
            idField: "gs_id",
            loadMsg: "${i18n('oper.loading')}",
            tbid: "tb-zh"
        });
    });

    var zh_tool = {
        add: function () {
            rsdp.createDialog({
                url: "${ctxPath}/system/zh/add",
                title: "${i18n('msg.zh.new')}",
                width: 500,
                height: 350,
                btnArray: [{
                    cls: 'easyui-linkbutton button-blue',
                    iconCls: 'fa fa-check fa-lg',
                    text: "${i18n('btn.save')}",
                    handler: function () {
                        zh_tool.add_save();
                    }
                },
                    {
                        iconCls: 'fa fa-close fa-lg',
                        text: "${i18n('btn.close')}",
                        handler: function () {
                            rsdp.closeDialog();
                        }
                    }]
            });
            //清除关闭数据没清空问题
            $("#form-add").form('clear');
        },
        add_save: function () {
            rsdp.ajaxform({
                fid: "form-add",
                url: "${ctxPath}/system/zh/addSave",
                func: function () {
                    rsdp.closeDialog();
                    dg_zh.datagrid("reload");
                    dg_zh.datagrid("clearSelections");
                }
            });
        },
        edit: function () {
            var row = getSelectRow('#dg-zh');
            if (row) {
                rsdp.createDialog({
                    url: "${ctxPath}/system/zh/edit",
                    title: "${i18n('msg.zh.edit')}",
                    width: 500,
                    height: 350,
                    param: {id: row.ZH_ID},
                    btnArray: [{
                        cls: 'easyui-linkbutton button-blue',
                        iconCls: 'fa fa-check fa-lg',
                        text: "${i18n('btn.save')}",
                        handler: function () {
                            zh_tool.edit_save();
                        }
                    },
                        {
                            iconCls: 'fa fa-close fa-lg',
                            text: "${i18n('btn.close')}",
                            handler: function () {
                                rsdp.closeDialog();
                            }
                        }]
                });
            }
            else {
                //layer.msg("${i18n('msg.row.select')}", {time: 1000});
                rsdp.msg("${i18n('msg.row.select')}", {time: 1000});
            }
        },
        edit_save: function () {
            rsdp.ajaxform({
                fid: "form-edit",
                url: "${ctxPath}/system/zh/editSave",
                func: function () {
                    rsdp.closeDialog();
                    dg_zh.datagrid("reload");
                    dg_zh.datagrid("clearSelections");
                }
            });
        },
        refresh: function () {
            rsdp.refresh();
        },
        search: function () {
            dg_zh.datagrid('load', {
                zhlx: $('#sel_zhlxs').combobox('getValue'),
                zhmc: $('#zhmc').val(),
                zhbh: $('#zhbh').val()
            });
            dg_zh.datagrid("clearSelections");
        },
        delete: function () {
            var row = getSelectRow('#dg-zh');
            //console.log(row);
            if (row) {
                rsdp.ajaxPostJson({
                    url: "${ctxPath}/system/zh/delete",
                    param: {"id": row.ZH_ID},
                    cstr: "${i18n('msg.zh.delete')}",
                    func: function () {
                        dg_zh.datagrid("reload");
                        dg_zh.datagrid("clearSelections");
                    }
                });
            }
            else {
                //layer.msg("${i18n('msg.row.select')}", {time: 1000});
                rsdp.msg("${i18n('msg.row.select')}", {time: 1000});
            }
        },
        import: function () {
            rsdp.createDialog({
                url: "${ctxPath}/system/zh/import",
                title: "${i18n('msg.zh.import')}",
                width: 500,
                height: 200,
                btnArray: [{
                    cls: 'easyui-linkbutton button-blue',
                    iconCls: 'fa fa-check fa-lg',
                    text: "${i18n('btn.save')}",
                    handler: function () {
                        zh_tool.import_save();
                    }
                },
                    {
                        iconCls: 'fa fa-close fa-lg',
                        text: "${i18n('btn.close')}",
                        handler: function () {
                            rsdp.closeDialog();
                        }
                    }]
            });
        },
        import_save: function () {
            rsdp.ajaxUpload({
                fid: 'form-import',
                url: "${ctxPath}/system/zh/importSave",
                loading: "${i18n('oper.upload')}",
                success: function () {
                    rsdp.closeDialog();
                    dg_zh.datagrid("reload");
                    dg_zh.datagrid("clearSelections");
                }

            });
        },
        download: function () {
            var form = $("<form>");
            form.attr('style', 'display:none');
            form.attr('target', '');
            form.attr('method', 'post');
            form.attr('action', "${ctxPath}/system/zh/download");
            $('body').append(form);
            form.submit();
            form.remove();
        }
    }
</script>